package ua.zwpp.java8.concurrency;

import java.util.concurrent.CompletableFuture;

/**
 * Created by vitaly on 17.09.14.
 *
 * http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletableFuture.html
 */
public class CompletableFutureDemo {
    public static void main(String[] args) {
        final CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
            //...long running...
            return "42";
        });
        // these transformations are neither executed immediately nor blocking
        CompletableFuture<Double> f2 = f1.thenApply(Integer::parseInt).thenApply(r -> r * r * Math.PI);

        CompletableFuture<String> safe = f1.exceptionally(ex -> "We have a problem: " + ex.getMessage());
    }
}
